/*
 * main.cpp
 *
 *  Created on: 30.03.2014
 *      Author: Medvedeva Anna
 */

#define _CRTDBG_MAP_ALLOC

#include <iostream>
#include <utility>
#include <time.h>
#include "Graph.h"
#include <fstream>
#include <cstring>
#include <sys/time.h>
#include <sys/resource.h>
#include <stdlib.h>

using namespace std;

const int NUMB_TESTS = 100;

int count = NUMB_TESTS * 3;

void PrintCount() {std::cout << "non free: " << count << std::endl;}

void* operator new[](size_t size)
{
  count++;
  return malloc(size);
}

void operator delete[](void *p)
{
  count--;
  free(p);
}
Graph::~Graph(){
	count--;
}
Graph::Graph(){
	count++;
}

int main(int argc, char **argv)
{
	struct rusage ru;
	string name;
	ifstream in("input.txt");	count--;
	ofstream out("output.txt");	count--;

	cout.rdbuf(out.rdbuf());
	clock_t start,finish;

	start=clock();
	out << "Полные графы:\n\n";
	for (int i = 0; i < NUMB_TESTS; i++) {
		out << "graph number "<< i+1 << endl;
		Graph graph;
		graph.make_compact_digraph(in);
		graph.dfs();
		graph.bfs(0);
		topological_sort(graph);
		cout << endl<< endl;
	}
	finish=clock();
	out<<"\nTIME Полные = ";
	out<<(double)(finish-start)/CLOCKS_PER_SEC << endl << endl;

	start=clock();
	out << "Случайные графы:\n\n";
		for (int i = 0; i < NUMB_TESTS; i++) {
			out << "graph number "<< i+1 << endl;
			Graph graph;
			graph.make_compact_digraph(in);
			graph.dfs();
			graph.bfs(0);
			topological_sort(graph);
			finish=clock();
			cout << endl << endl;
		}
	finish=clock();
	out<<"\nTIME Случайные= ";
	out<<(double)(finish-start)/CLOCKS_PER_SEC << endl << endl;
	start=clock();

	out << "Ациклические графы:\n\n";
		for (int i = 0; i < NUMB_TESTS; i++) {
			out << "graph number "<< i+1 << endl;
			Graph graph;
			graph.make_compact_digraph(in);
			graph.dfs();
			graph.bfs(0);
			topological_sort(graph);
			cout << endl<< endl;
		}
		finish=clock();

	out<<"\nTIME Ациклические = ";
	out<<(double)(finish-start)/CLOCKS_PER_SEC << endl;

	PrintCount();

	out << "Процесс занял :" << ru.ru_maxrss << " килобайт памяти\n"<< endl;
	in.close();
	out.close();
	return 0;

}



